﻿package fpc.layouts;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import fpc.IAutoSizable;
import fpc.layouts.ILayout;
import fpc.utils.Herald;
import fpc.layouts.ILayoutable;

class ALayout implements ILayout, implements IAutoSizable
{
	public var heraldAddChild(default, null):Herald<ILayoutable>;
	
	public var heraldRemoveChild(default, null):Herald<ILayoutable>;
	
	public var heraldChange(default, null):Herald<ILayout>;
	
	public function new() 
	{
		heraldAddChild = new Herald();
		heraldRemoveChild = new Herald();
		heraldChange = new Herald();
		_autoSize = true;
		width = 0;
		height = 0;
		_gapX = _gapY = 4;
	}
	
	public function arrange()
	{
		
	}
	
	public function removeAll()
	{
		
	}
	
	public function iterator():Iterator<ILayoutable>
	{
		return null;
	}
	
	inline function disableComponent(component:ILayoutable)
	{
		var herald = component.heraldResize;
		herald.remove(onComponentResize);
		herald.disableOn();
	}
	
	inline function enableComponent(component:ILayoutable)
	{
		var herald = component.heraldResize;
		herald.disableOff();
		herald.dispatch(component);
		herald.add(onComponentResize);
	}
	
	function onComponentResize(component:ILayoutable)
	{
		heraldChange.dispatch(this);
	}
	
	public var width:Float;
	
	public var height:Float;
	
	public var autoSize(getAutoSize, setAutoSize):Bool;
	var _autoSize:Bool;
	function getAutoSize()
	{
		return _autoSize;
	}
	function setAutoSize(value:Bool)
	{
		if (value != value)
		{
			heraldChange.dispatch(this);
		}
		_autoSize = value;
		return value;
	}
	
	public var gapX(getGapX, setGapX):Float;
	var _gapX:Float;
	function getGapX()
	{
		return _gapX;
	}
	function setGapX(value)
	{
		_gapX = value;
		heraldChange.dispatch(this);
		return value;
	}
	
	public var gapY(getGapY, setGapY):Float;
	var _gapY:Float;
	function getGapY()
	{
		return _gapY;
	}
	function setGapY(value)
	{
		_gapY = value;
		heraldChange.dispatch(this);
		return value;
	}
}